/**
 * 保修表单模型
 */
package dms.model.form;

import java.util.Date;

import dms.model.Building;
import dms.model.Dormitory;
import dms.model.role.DormSupervisor;
import dms.model.role.Student;

/**
 * @author 李健
 *
 */
public class Repair {
	
	private Long id;
	private Dormitory dormitory;
	private Student student;
	private String title;
	private String reason;
	
	private Date requestDate;
	private DormSupervisor dormSupervisor;
	private Building building;
	private ProcessStatus status;
	
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	/**
	 * @return the dormSupervisor
	 */
	public DormSupervisor getDormSupervisor() {
		return dormSupervisor;
	}
	/**
	 * @param dormSupervisor the dormSupervisor to set
	 */
	public void setDormSupervisor(DormSupervisor dormSupervisor) {
		this.dormSupervisor = dormSupervisor;
	}
	/**
	 * @return the building
	 */
	public Building getBuilding() {
		return building;
	}
	/**
	 * @param building the building to set
	 */
	public void setBuilding(Building building) {
		this.building = building;
	}
	/**
	 * 
	 */
	public Repair() {
		super();
		this.setStatus(new ProcessStatus(false, false));
	}
	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	private void setId(Long id) {
		this.id = id;
	}
	/**
	 * @return the dormitory
	 */
	public Dormitory getDormitory() {
		return dormitory;
	}
	/**
	 * @param dormitory the dormitory to set
	 */
	public void setDormitory(Dormitory dormitory) {
		this.dormitory = dormitory;
	}
	/**
	 * @return the student
	 */
	public Student getStudent() {
		return student;
	}
	/**
	 * @param student the student to set
	 */
	public void setStudent(Student student) {
		this.student = student;
	}
	
	/**
	 * @return the reason
	 */
	public String getReason() {
		return reason;
	}
	/**
	 * @param reason the reason to set
	 */
	public void setReason(String reason) {
		this.reason = reason;
	}
	/**
	 * @return the requestDate
	 */
	public Date getRequestDate() {
		return requestDate;
	}
	/**
	 * @param requestDate the requestDate to set
	 */
	public void setRequestDate(Date requestDate) {
		this.requestDate = requestDate;
	}
	/**
	 * @return the processDate
	 */
	/**
	 * @return the status
	 */
	public ProcessStatus getStatus() {
		return status;
	}
	/**
	 * @param status the status to set
	 */
	public void setStatus(ProcessStatus status) {
		this.status = status;
	}
	public  void process() {
		this.getStatus().setProcessed(true);
		this.getStatus().setProcessDate(new Date());
	}
	
	public  void unProcess() throws Exception {
		//如果已处理完了，则不能unProcess
		if (this.getStatus().isApplied()) {
			throw new Exception("维修单已经处理完毕，不能取消受理");
		}
		this.getStatus().setProcessed(false);
		this.getStatus().setProcessDate(null);
	}
	
	public void apply() {
		this.getStatus().setProcessDate(new Date());
		this.getStatus().setProcessed(true);
		this.getStatus().setApplied(true);
		this.getStatus().setApplyDate(new Date());
	}
	
	public void unApply() {
		
		this.getStatus().setApplied(false);
		this.getStatus().setApplyDate(null);
	}
	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}
	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Repair other = (Repair) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
}
